# $Id: Makefile,v 1.89 1999/04/19 17:53:48 donwm Exp $
# Copyright (C) 1994 - 1998, Hewlett-Packard Company, all rights reserved.
# Taken from E1431 library, heavily modified by Eric Backus

SHELL		= /bin/sh

E1432_BASE	= /opt/e1432
E1432_INC	= $(E1432_BASE)/include
E1432_LIB	= $(E1432_BASE)/lib
E1432_HOSTLIB	= $(E1432_BASE)/hostlib
VXIPNP_BASE	= /opt/vxipnp/hpux/hpe1432
DATE=`date +"%y%b%d%H%M"`

CC		= cc
AR		= ar
OPTIMIZE	= -O
COMCFLAGS	= -D_HPUX_SOURCE -Aa +w1
CFLAGS		= $(COMCFLAGS) $(OPTIMIZE)
LNFLAGS		= $(CFLAGS) -x

PNP_INC		= /opt/vxipnp/hpux/include
PNP_DEFS	= -DVXIPNP -DHAVE_VTL -DINSTR_CALLBACKS -DINSTR_REAL32
PNP_CFLAGS	= $(CFLAGS) $(PNP_DEFS) -I $(PNP_INC) +Z

E1485_BASE	= /opt/e1485
E1485_INC	= $(E1485_BASE)/include
E1485_CC	= $(E1485_BASE)/gcc/gcc
E1485_AR	= $(E1485_BASE)/gcc/gar
E1485_CFLAGS	= -DE1485_SOURCE -I $(E1485_INC) -ansi -O2 -B$(E1485_BASE)/gcc/

INCS		= e1432.h e1432i.h err1432.h\
			global.h machType.h sema.h syscalls.h hpe1432.h

CFILES		= analog.c auto.c data.c debugio.c decomp.c diag1432.c\
			display.c error.c filter.c fwrev.c getdata.c\
			hpe1432.c i2c.c install.c intr.c io.c machine.c\
			meas.c modgroup.c octave.c parms.c sca.c\
			selftest.c set.c siclimap.c srcdata.c\
			testmem.c testsca.c testsbst.c timing.c\
			trigger.c vtlio.c zap.c

DIAG_ASC	= diag_son_a.asc diag_son_b.asc

OBJS		= $(CFILES:.c=.o)
PTMP		= $(CFILES:.c=.pic)
POBJS		= $(CFILES:.c=.pic.o)
PNP_TMP		= $(CFILES:.c=.pnppic)
PNP_OBJS	= $(CFILES:.c=.pnppic.o)
E1485_TMP	= $(CFILES:.c=.e1485)
E1485_OBJS	= $(CFILES:.c=.e1485.o)

# These are used to test HP-UX version, evals to 1 if true
#  HP-UX 9.x
HPUX9PX		= `uname -a|fgrep ".09."|wc -l`
#  HP-UX 10.2x
HPUX10P2	= `uname -a|fgrep ".10.2"|wc -l`

# Teach make how to create all our different types of object files
.SUFFIXES:	.pic .e1485 .pnppic
.c.pic:
	$(CC) $(CFLAGS) -DVXIPNP +Z -c $< -o $@
	rm -f $@.o
	ln -f $@ $@.o
.c.e1485:
	$(E1485_CC) $(E1485_CFLAGS) -c $< -o $@
	rm -f $@.o
	ln -f $@ $@.o
.c.pnppic:
	rm -f visa.h visatype.h vpptype.h
	$(CC) $(PNP_CFLAGS) -c $< -o $@
	rm -f $@.o
	ln -f $@ $@.o

all:	lib1432.a lib1432.sl hpe1432.sl lib1432.pio libd1432.a llib-l1432.ln hpe1432.defnew hpe1432.hnew hpe1432.basnew

run:

monitor:
	rm -f hpe1432.h
	cp hpe1432.hedf hpe1432.h
	$(MAKE) COMCFLAGS="$(COMCFLAGS) -DREQUEST"

# Compare with existing files, to avoid unnecessary remakes in other
# directories
install:	all
	cmp -s lib1432.a $(E1432_LIB)/lib1432.a ||\
		cp -f lib1432.a $(E1432_LIB)
	chmod -w $(E1432_LIB)/lib1432.a
	cmp -s lib1432.sl $(E1432_LIB)/lib1432.sl ||\
		cp -f lib1432.sl $(E1432_LIB)
	chmod -w $(E1432_LIB)/lib1432.sl
	cmp -s lib1432.pio $(E1432_LIB)/lib1432.pio ||\
		cp -f lib1432.pio $(E1432_LIB)
	chmod -w $(E1432_LIB)/lib1432.pio
	cmp -s libd1432.a $(E1432_LIB)/libd1432.a ||\
		cp -f libd1432.a $(E1432_LIB)
	chmod -w $(E1432_LIB)/libd1432.a
	cmp -s llib-l1432.ln $(E1432_LIB)/llib-l1432.ln ||\
		cp -f llib-l1432.ln $(E1432_LIB)
	chmod -w $(E1432_LIB)/llib-l1432.ln
	cmp -s e1432.h $(E1432_INC)/e1432.h ||\
		cp -f e1432.h $(E1432_INC)
	chmod -w $(E1432_INC)/e1432.h
	cmp -s err1432.h $(E1432_INC)/err1432.h ||\
		cp -f err1432.h $(E1432_INC)
	chmod -w $(E1432_INC)/err1432.h
	cmp -s machType.h $(E1432_INC)/machType.h ||\
		cp -f machType.h $(E1432_INC)
	chmod -w $(E1432_INC)/machType.h
	cmp -s hpe1432.unixhlp $(VXIPNP_BASE)/hpe1432.hlp ||\
		cp -f hpe1432.unixhlp $(VXIPNP_BASE)/hpe1432.hlp
	chmod -w $(VXIPNP_BASE)/hpe1432.hlp
	cmp -s hpe1432.fp $(VXIPNP_BASE)/hpe1432.fp ||\
		cp -f hpe1432.fp $(VXIPNP_BASE)
	chmod -w $(VXIPNP_BASE)/hpe1432.fp
	cmp -s hpe1432.h $(VXIPNP_BASE)/hpe1432.h ||\
		cp -f hpe1432.h $(VXIPNP_BASE)
	chmod -w $(VXIPNP_BASE)/hpe1432.h
	cmp -s hpe1432.sl $(VXIPNP_BASE)/hpe1432.sl ||\
		cp -f hpe1432.sl $(VXIPNP_BASE)/hpe1432.sl ;\
	chmod -w $(VXIPNP_BASE)/hpe1432.sl
	cp -f Makefile README $(CFILES) $(INCS) $(DIAG_ASC) $(E1432_HOSTLIB)
	cp -f diag1432.def diag1432.mak $(E1432_HOSTLIB)
	cp -f e1432.bas e1432.def e1432.mak err1432.bas $(E1432_HOSTLIB)
	cp -f hpe1432.bas hpe1432.cnt hpe1432.def $(E1432_HOSTLIB)
	cp -f hpe1432.kb hpe1432.matio $(E1432_HOSTLIB)
	cp -f hpe1433.kb hpe1434.kb plugadder $(E1432_HOSTLIB)
	cp -f lintlib.c llib-l1432.c $(E1432_HOSTLIB)
	if [ $(HPUX9PX) -eq 1 ]; then\
	    cp -f visa.h visatype.h vpptype.h $(E1432_HOSTLIB);\
	fi

lint:		$(CFILES) $(INCS) $(DIAG_ASC) lintlib.c
	lint $(LNFLAGS) $(CFILES) lintlib.c -lm > lint

clean:
	rm -f $(OBJS) $(PTMP) $(POBJS) $(PNP_TMP) $(PNP_OBJS)
	rm -f $(E1485_TMP) $(E1485_OBJS)
	rm -f lib1432.a lib1432.sl lib1432.pio libd1432.a llib-l1432.ln
	rm -f lib1432.o hpe1432.sl hpe1432.sl9 hpe1432.sl10
	rm -f hpe1432.def hpe1432.h hpe1432.bas hpe1432.defnew hpe1432.hnew hpe1432.basnew
	rm -f rev.c rev.o rev.pic rev.pic.o rev.e1485 rev.e1485.o
	rm -f rev.pnppic rev.pnppic.o lint *~

debug:
	$(MAKE) OPTIMIZE=-g lib1432.sl

malloc_trace:
	$(MAKE) COMCFLAGS="$(COMCFLAGS) -DMALLOC_TRACE -I/usr/local/include"

# This is now in HMS like the rest of the files
#machType.h:
#	co -q /nfs/labvxi/users/toolkit/commSrc/spos/$@,v

llib-l1432.ln:	llib-l1432.c $(INCS) $(DIAG_ASC)
	lint $(LNFLAGS) -c llib-l1432.c

$(OBJS) $(PTMP) $(PNP_TMP) $(E1485_TMP):	$(INCS)

# Only testsca.c uses diag_son_*.asc so make expicit dependency
testsca.o testsca.pic testsca.pnppic testsca.e1485:	$(DIAG_ASC)

# Only zap.c uses son_ee.asc so make expicit dependency
zap.o zap.pic zap.pnppic zap.e1485:	son_ee.asc

# Archive library
lib1432.a:	$(OBJS)
	echo "const char _e1432buildId1[] =" > rev.c
	if [ $(HPUX9PX) -eq 1 ]; then\
	    echo "    \"@(""#)\$$Id: E1432 Library for HP-UX 9.0x, Rev: \c" >> rev.c;\
	else\
	    echo "    \"@(""#)\$$Id: E1432 Library for HP-UX 10.20, Rev: \c" >> rev.c;\
	fi
	$(MAKE) rev.o
	rm -f $@
	ar rc $@ $(OBJS) rev.o

# Shared library
lib1432.sl:	$(PTMP)
	echo "const char _e1432buildId1[] =" > rev.c
	if [ $(HPUX9PX) -eq 1 ]; then\
	    echo "    \"@(""#)\$$Id: E1432 Shared Library for HP-UX 9.0x, Rev: \c" >> rev.c;\
	else\
	    echo "    \"@(""#)\$$Id: E1432 Shared Library for HP-UX 10.20, Rev: \c" >> rev.c;\
	fi
	$(MAKE) rev.pic
	rm -f $@
	ld -o $@ -b $(POBJS) rev.pic.o

# VXI Plug&Play shared library
hpe1432.sl:	FORCE
	if [ ! -f hpe1432.sl ]; then rm -f hpe1432.sl9 hpe1432.sl10; fi
	if [ $(HPUX9PX) -eq 1 ]; then\
	    $(MAKE) REV=$(REV) hpe1432.sl9;\
	else\
	    $(MAKE) REV=$(REV) hpe1432.sl10;\
	fi

hpe1432.sl10:	$(PNP_TMP)
	echo "const char _e1432buildId1[] =" > rev.c
	if [ $(HPUX9PX) -eq 1 ]; then\
	    echo "    \"@(""#)\$$Id: E1432 Plug&Play Shared Library for HP-UX 9.0x, Rev: \c" >> rev.c;\
	else\
	    echo "    \"@(""#)\$$Id: E1432 Plug&Play Shared Library for HP-UX 10.20, Rev: \c" >> rev.c;\
	fi
	$(MAKE) rev.pnppic
	rm -f hpe1432.sl
	ld -o hpe1432.sl +b /opt/vxipnp/hpux/bin -b $(PNP_OBJS) rev.pnppic.o -lvisa
	touch hpe1432.sl10

hpe1432.sl9:	lib1432.sl
	sleep 1
	rm -f hpe1432.sl
	ln -f lib1432.sl hpe1432.sl
	touch hpe1432.sl9

# Position-independent object file
lib1432.o:	$(PTMP)
	echo "const char _e1432buildId1[] =" > rev.c
	if [ $(HPUX9PX) -eq 1 ]; then\
	    echo "    \"@(""#)\$$Id: E1432 PIC Object for HP-UX 9.0x, Rev: \c" >> rev.c;\
	else\
	    echo "    \"@(""#)\$$Id: E1432 PIC Object for HP-UX 10.20, Rev: \c" >> rev.c;\
	fi
	$(MAKE) rev.pic
	rm -f $@
	ld -o $@ -r $(POBJS) rev.pic.o

# Single object file that combines all position-independent object
# files in the library.  Longblock calls it .pio for unknown
# reasons(ask garya); we would like to eventually get rid of that
# name.
lib1432.pio:	lib1432.o
	sleep 1
	cp -f lib1432.o $@

# Download library for E1485
libd1432.a:	$(E1485_TMP)
	echo "const char _e1432buildId1[] =" > rev.c
	echo "    \"@(""#)\$$Id: E1432 Library for E1485, Rev: \c" >> rev.c
	$(MAKE) rev.e1485
	rm -f $@
	$(E1485_AR) rc $@ $(E1485_OBJS) rev.e1485.o

# Common rule for making the rev.c file linked into each library
rev.c:	FORCE
	if [ "${REV}" = "" ] ; then\
		echo "x.xx.xx \$$\";";\
	else\
		echo "${REV} \$$\";";\
	fi >> rev.c
	echo "const char _e1432buildId2[] =" >> rev.c
	echo "    \"@(""#)\$$""Id: $@ built: ${LOGNAME}@`uname -n`, `date` \$$\";" >> rev.c

# Force rev.c to get remade even if it already exists
FORCE:

###########################################################################
# Plug and Play make rules

# Similar to the older ~semaphore/pnp-tools/makedef, this forces
# hpe1432.def to be made from a manually updated hpe1432.h file.
# Eventually we should just make hpe1432.def depend on hpe1432.h, and
# remove hpe1432.def from HMS (put it into the semaphore.archive
# tree).  But I'll wait a few more revs before doing this (currently
# at X.04.08).
hpe1432.defnew:	hpe1432.hnew
	rm -f hpe1432.defnew hpe1432.def
	echo EXPORTS > hpe1432.defnew
	grep "_VI_FUNC hpe1432" hpe1432.h | cut -d" " -f3 >> hpe1432.defnew
	cat defadder >> hpe1432.defnew
	sort -u hpe1432.defnew > hpe1432.def

hpe1432.hnew: phpe1432.h plugadder 
	rm -f hpe1432.hnew hpe1432.h
	cat phpe1432.h | sed -e "1,10d" -e "s%HPE1432_MIN_32  -2147483648%HPE1432_MIN_32  (-2147483647 -1)%" > hpe1432.hnew
	cat plugadder hpe1432.hnew > hpe1432.h

hpe1432.basnew: phpe1432.bas basadder
	rm -f hpe1432.basnew hpe1432.bas
	cat phpe1432.bas | sed -e "1,2d" -e "s%hpe1432.dll%hpe1432_32.dll%" |grep -v hpe1432_callbackInstall | grep -v hpe1432_readFloat32Data | grep -v hpe1432_readFloat32Spectrum | grep -v hpe1432_getCurrentValue32 > hpe1432.basnew
	cat basadder hpe1432.basnew > hpe1432.bas

hpe1432.h: hpe1432.hnew

hpe1432.bas: hpe1432.basnew

hpe1432.def: hpe1432.defnew


